using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using THSLib;using THSERP.BaseProvider;

namespace THSERP.Modules.Report
{
    public partial class RP011 : ReportForm
    {
        public RP011()
        {
            InitializeComponent();
        }

        private void RP011_Load(object sender, EventArgs e)
        {
            fld_lkeFK_ARCustomerID.Screen = this;
            fld_lkeFK_ARCustomerID.InitializeControl();
            if (!Module.Controls.Contains(fld_lkeFK_ARCustomerID.Name))
                Module.Controls.Add(fld_lkeFK_ARCustomerID.Name, fld_lkeFK_ARCustomerID);

            fld_lkeARSaleOrderNo.Screen = this;
            fld_lkeARSaleOrderNo.InitializeControl();
            fld_dgcARRP011Invoices.Screen = this;
            fld_dgcARRP011Invoices.InitializeControl();

            fld_btnApply_Click(new object(), new EventArgs());
        }

        private void fld_btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void fld_btnApply_Click(object sender, EventArgs e)
        {
            StringBuilder queryBuilder = new StringBuilder();
            queryBuilder.Append(GenerateSearchQuery(THSUtil.GetTableNameFromBusinessObjectType(typeof(ARInvoicesInfo))));
            queryBuilder.Append(String.Format("AND ARInvoiceTypeCombo = '{0}'", ADConfigValueUtility.cstOpenDocumentTypeLayBy));
            if ((int)fld_lkeARSaleOrderNo.EditValue > 0)
            {
                String strSaleOrderNumber = ((ARSaleOrdersInfo)new ARSaleOrdersController().GetObjectByID((int)fld_lkeARSaleOrderNo.EditValue)).ARSaleOrderNo;
                queryBuilder.Append(String.Format("AND ARInvoiceReference = '{0}'", strSaleOrderNumber));
            }
            DataSet ds = new ARInvoicesController().GetDataSet(queryBuilder.ToString());
            fld_dgcARRP011Invoices.DataSource = ds.Tables[0];
            fld_dgcARRP011Invoices.RefreshDataSource();
        }
    }
}